package com.anlu.pattern.structrue.proxy.dynamic;

import com.anlu.pattern.structrue.proxy.staticproxy.HouseService;
import com.anlu.pattern.structrue.proxy.staticproxy.Renter;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * <p>
 * Description:动态代理的测试类
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/5/5 15:07
 */
public class ProxyTest {
    public static void main(String[] args) {
        //创建被代理的中介对象
        HouseService renter = new Renter();
        //创建InvocationHander对象
        InvocationHandler renterHandler = new RenterInvocationHandler<HouseService>(renter);

        HouseService renterProxy = (HouseService)Proxy.newProxyInstance(HouseService.class.getClassLoader(),new Class<?>[]{HouseService.class}, renterHandler);
        renterProxy.rentHouse();

    }
}
